package com.hxzy.shop.utils.esayExcel;

import com.alibaba.excel.metadata.Head;
import com.alibaba.excel.write.metadata.style.WriteCellStyle;
import com.alibaba.excel.write.style.HorizontalCellStyleStrategy;
import org.apache.poi.ss.usermodel.*;

import java.util.List;

/**
 * @Description
 * @Author tu-jia-hao
 * @Data 2022/9/27 16:42
 */
public class CustomHandler extends HorizontalCellStyleStrategy {
    public CustomHandler(WriteCellStyle headWriteCellStyle, List<WriteCellStyle> contentWriteCellStyleList) {
        super(headWriteCellStyle, contentWriteCellStyleList);
    }

    public CustomHandler(WriteCellStyle headWriteCellStyle, WriteCellStyle contentWriteCellStyle) {
        super(headWriteCellStyle, contentWriteCellStyle);
    }
    @Override
    protected void setContentCellStyle(Cell cell, Head head, Integer relativeRowIndex) {
        if (head.getFieldName().endsWith("是否赠品")) {
            // 如果该列的名字以 Record 结尾，则进行单独的样式设置
            Workbook wb = cell.getSheet().getWorkbook();
            CellStyle cellStyle = wb.createCellStyle();
            // 左对齐，垂直居中对齐
            cellStyle.setAlignment(HorizontalAlignment.LEFT);
            cellStyle.setVerticalAlignment(VerticalAlignment.CENTER);
            // 边框线
            cellStyle.setBorderLeft(BorderStyle.THIN);
            cellStyle.setBorderRight(BorderStyle.THIN);
            cellStyle.setBorderBottom(BorderStyle.THIN);
            cellStyle.setBorderTop(BorderStyle.THIN);
            cellStyle.setFillForegroundColor(Short.valueOf("17"));
            cellStyle.setFillBackgroundColor(Short.valueOf("17"));
            // 自动换行
            cellStyle.setWrapText(true);
            cell.setCellStyle(cellStyle);
        } else {
            super.setContentCellStyle(cell, head, relativeRowIndex);
        }
    }
}
